Skip to content

Fix: delete an in-memory context under the key it was stored as - #336

Merged
briankane merged 1 commit into
kubevela:mainfrom
marcus-beauregard:fix/in-memory-context-delete-key
Nov 21, 2026
Merged

briankane merged 1 commit into
kubevela:mainfrom
marcus-beauregard:fix/in-memory-context-delete-key

Conversation

@marcus-beauregard

@marcus-beauregard marcus-beauregard commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Description of your changes

Fixes #333

DeleteInMemoryContext built its key as workflow-<app>-context, but every write and read goes through contextKey, which is <namespace>/workflow-<app>-context (getKey, storage.go:39). The two could never match, so the delete was a no-op and the context of a deleted Application stayed in memory for the life of the controller whenever EnableInMemoryContext was on.

  • DeleteInMemoryContext(appName) now takes (appName, namespace) and builds the key with contextKey(generateStoreName(appName), namespace), the same helpers the store writes with. fmt is no longer needed in the file.
  • New TestDeleteInMemoryContext: deleting removes that namespace's context, leaves another namespace's alone, defaults an empty namespace the same way reads and writes do (both directions), and is a no-op for a context that was never stored.

Two things worth your attention:

  1. The signature change breaks the call site in kubevela/kubevela (application_controller.go calls MemStore.DeleteInMemoryContext(app.Name)); that repo has to pass app.Namespace after it bumps this module. The issue says the same, and a variadic or an extra method would leave the broken no-op delete reachable.
  2. pkg/context/storage_test.go still imported github.com/crossplane/crossplane-runtime/pkg/test after the v2 dependency bump, so go test ./pkg/context/ fails to build on main right now with missing go.sum entry for module providing package github.com/crossplane/crossplane-runtime/pkg/test. I changed that one line to /v2/pkg/test; otherwise the package's tests, including the new one, cannot run. Nothing else from the v1 module is imported anywhere in the repo (git grep crossplane-runtime/pkg), so this is the only stale import.

I have:

  • Read and followed KubeVela's contribution process.
  • Related Docs updated properly. (No user-facing configuration changed.)
  • Run make reviewable for the packages I touched: gofmt -l pkg/context clean, go vet ./pkg/context/ clean. I did not run the full target because it regenerates manifests and CRDs unrelated to this change.
  • Added backport release-x.y labels.

How has this code been tested

  • go test ./pkg/context/ — ok, all tests in the package pass.
  • Fault injection: restoring the old key (contextKey(generateStoreName(app.Name), ""), namespace dropped) makes the new test fail at storage_test.go:94 with "delete should remove the stored context"; the fix makes it pass. So the test fails for the reason the issue describes and not only for the signature.
  • The new test drives the exported methods only; the controller-level effect (a deleted Application's context going away) is not exercised here because MemStore is package-global and the call site lives in the other repo.

Special notes for your reviewer

The namespace argument is deliberately explicit rather than defaulted inside the delete: the store already treats "" as default, and the test pins both directions, so a caller that forgets app.Namespace gets default — which is what NewContext writes for a cluster-scoped or default-namespace Application.


Summary by cubic

Fixes in-memory context deletion so the stored context of a deleted Application is actually removed instead of remaining in memory for the life of the controller.

DeleteInMemoryContext built its key as workflow-<app>-context, but every read and write uses <namespace>/workflow-<app>-context; the keys never matched, so the delete was a no-op.

  • The method now takes (appName, namespace) and builds the key with the same helpers reads and writes use. This is a breaking change for callers, who must pass app.Namespace.
  • Adds TestDeleteInMemoryContext covering per-namespace deletion, empty-namespace defaulting in both directions, and no-ops on never-stored contexts.
  • Fixes a stale crossplane-runtime v1 import in pkg/context/storage_test.go that broke go test ./pkg/context/.

Written for commit fda4d75. Summary will update on new commits.

View guided diff

DeleteInMemoryContext built its key as "workflow-<app>-context", while
every write and read goes through contextKey(name, namespace), which is
"<namespace>/workflow-<app>-context". The keys could never match, so the
delete was a no-op and the context of a deleted Application stayed in
memory for the life of the controller.

Take the namespace the same way GetInMemoryContext does and build the key
with contextKey and generateStoreName. The KubeVela call site has to pass
app.Namespace after it bumps this repo.

Signed-off-by: Marcus Beauregard <marcus.beauregard.developer@gmail.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

View guided diff | Re-trigger cubic

@briankane briankane added type/bug Something isn't working area/data-passing Inputs, outputs, parameterKey and the workflow context store (pkg/hooks, pkg/context) labels Nov 21, 2026
@briankane
briankane merged commit 593f538 into kubevela:main Nov 21, 2026
20 checks passed
@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.64%. Comparing base (d7db9c4) to head (fda4d75).
⚠️ Report is 55 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #336       +/-   ##
===========================================
+ Coverage   62.49%   80.64%   +18.15%     
===========================================
  Files          62       88       +26     
  Lines        4415     7053     +2638     
===========================================
+ Hits         2759     5688     +2929     
- Misses       1324     1365       +41     
+ Partials      332        0      -332     
Flag Coverage Δ
e2etests 37.46% <0.00%> (?)
unit-test 75.03% <100.00%> (+12.54%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/data-passing Inputs, outputs, parameterKey and the workflow context store (pkg/hooks, pkg/context) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] DeleteInMemoryContext never removes anything, so in-memory contexts pile up

2 participants